Use case: Starting a write/read in interrupt mode ¶
Starting a write/read operation in interrupt mode.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
/* Perform the init and configuration as per the first use case */
OSPI_HandleTypeDef ospi;
OSPI_RegularCmdTypeDef sCommand = {0};
/* Prepare command parameters in sCommand (instruction/address/data modes, etc.) */
/* Start command sequence in interrupt mode */
if (HAL_OSPI_Command_IT(&ospi, &sCommand) != HAL_OK)
{
Error_Handler();
}
/* Called from HAL_OSPI_IRQHandler() context */
void HAL_OSPI_CmdCpltCallback(OSPI_HandleTypeDef *hospi)
{
HAL_OSPI_SetFifoThreshold(hospi, 4);
/* Transmit in interrupt mode */
HAL_OSPI_Transmit_IT(hospi, pTxData);
}
/* Called from HAL_OSPI_IRQHandler() context */
void HAL_OSPI_TxCpltCallback(OSPI_HandleTypeDef *hospi)
{
/* Optionally send next command before receiving */
HAL_OSPI_Command(hospi, &sCommand, OSPI_TIMEOUT);
HAL_OSPI_Receive_IT(hospi, pRxData);
}
/* Called from HAL_OSPI_IRQHandler() context */
void HAL_OSPI_RxCpltCallback(OSPI_HandleTypeDef *hospi)
{
/* Transfer complete */
(void)hospi;
}
|
/* Perform the init and configuration as per the first use case */
hal_xspi_handle_t xspi;
hal_xspi_regular_cmd_t command = {0};
/* Prepare command parameters in command (instruction/address/data modes, etc.) */
/* Start command sequence in interrupt mode */
if (HAL_XSPI_SendRegularCmd_IT(&xspi, &command, XSPI_TIMEOUT) != HAL_OK)
{
Error_Handler();
}
/* Called from HAL_XSPI_IRQHandler() context */
void HAL_XSPI_CmdCpltCallback(hal_xspi_handle_t *hxspi)
{
/* Transmit in interrupt mode */
HAL_XSPI_Transmit_IT(hxspi, pTxData);
}
/* Called from HAL_XSPI_IRQHandler() context */
void HAL_XSPI_TxCpltCallback(hal_xspi_handle_t *hxspi)
{
/* Optionally send next command before receiving */
HAL_XSPI_SendRegularCmd(hxspi, &command, XSPI_TIMEOUT);
HAL_XSPI_Receive_IT(hxspi, pRxData);
}
/* Called from HAL_XSPI_IRQHandler() context */
void HAL_XSPI_RxCpltCallback(hal_xspi_handle_t *hxspi)
{
/* Transfer complete */
(void)hxspi;
}
|
Key changes ¶
In HAL2, OSPI interrupt APIs are replaced by XSPI interrupt APIs (for example,
HAL_OSPI_Command_IT()becomesHAL_XSPI_SendRegularCmd_IT()).In HAL2, the IRQ handling and callbacks are updated to XSPI naming.

